from models.Users import *
from google.appengine.api import users
import unittest
import logging

class D5UserTest(unittest.TestCase):
  """Class that will test the basic functionality of the User model"""
  def test_creation(self):
    """docstring for test_creation"""
    try:
      tmp_user = users.get_current_user()
      logging.info(tmp_user)
      myUser = D5User(google_user=users.get_current_user(), groups=["test"])
      myUser.put()
    
    except db.BadValueError, e:
      self.fail("should have saved the object")
      
  def test_fetch(self):
    """Test to see if you can get all the groups for a specific user"""
    # create the group and user for the test
    test_group = Group(title="test")
    test_group.put()
    
    test_group = Group(title="test2")
    test_group.put()
    
    myUser = D5User(google_user=users.get_current_user(), groups=["test"])
    myUser.put()
    
    myUser.groups.append("test2")
    myUser.put()
    
    # get the D5User from the db based on current google user
    curUser = users.get_current_user()
    query = D5User.all()
    query.filter("google_user = ", curUser)
    ourUser = query.get()
    
    # fetch all the groups for this user
    query = Group.all()
    query.filter("title IN ", ourUser.groups)
    
    result = query.fetch(10)
    
    self.assertEqual(2, len(result))
    
    